package com.huang.eduorder.controller;


import com.huang.eduorder.entity.Order;
import com.huang.eduorder.entity.PayLog;
import com.huang.eduorder.service.OrderService;
import com.huang.eduorder.service.PayLogService;
import com.hunag.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 支付日志表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-04-03
 */
@RestController
@RequestMapping("/eduorder/pay-log")
public class PayLogController {
    @Autowired
    private PayLogService service;


    @Autowired
    private OrderService orderService;

    @PostMapping("/createLog")
    public R createLog(@RequestBody PayLog payLog) {
        service.save(payLog);
        //修改 order状态
         String id = payLog.getOrderNo();
        orderService.updateById(new Order().setId(id));

        return R.ok();
    }

    @GetMapping("/getLog/{courseId}/{memberId}")
    public R getLog(@PathVariable("courseId") String courseId, @PathVariable("memberId") String memberId) {
//        PayLog log = service.findLog(courseId, memberId);
      Boolean isbuy= orderService.isBuy(courseId, memberId);

        return R.ok().data("buy", isbuy);
    }

}

